<template>



	<view class="page px22 pt1 relactive">
		<view class="font32 col2 fontw700 mt20">
			<text>基础信息</text>
		</view>

		<view class="relactive mt20  px24 pt1 br10 bgWhite border-box">
			<view class="mt40">
				<view class="">
					<text class="font44">{{productData.leave_score}}</text>分
				</view>
			</view>


			<view class="py40 px30 border-box flex flex-column flex-between  br16 mb22">

				<view class="  ">
					<view class="flex  flex-between align-center">
						<text class="mr22 font28">主体名称:</text>
						<text class="font32 font800">{{productData.main_name}}</text>
					</view>
				</view>

				<view class=" mt28  ">
					<view class="flex flex-between align-center">
						<text class="mr22">经营品种:</text>
						<text class="">{{productData.breed}}</text>
					</view>
				</view>
				<view class=" mt28  ">
					<view class="flex flex-between align-center">
						<text class="mr22">联系方式:</text>
						<text class="">{{productData.truename}} {{productData.phoneNumber}}</text>
					</view>
				</view>

				<view class="mt28 flex">

					<view class="mr22">
						<view class="px8 py4 border-box br4" style="background-color: #E6F7FF;">
							<text class="font24" style="color:#1590E2;">{{productData.main_type_name}}</text>
						</view>
					</view>
				</view>
				<view class="mt30 flex flex-between">
					<text>风险等级</text>
					<text v-if="productData.fx_level == 0">暂无</text>
					<text v-if="productData.fx_level == 1">A级风险</text>
					<text v-if="productData.fx_level == 2">B级风险</text>
					<text v-if="productData.fx_level == 3">C级风险</text>
				</view>
				<view class="flex align-center mt30">
					<image style="width:16rpx; height:23rpx;" class="mr14" src="/static/form/address.png" mode="">
					</image>
					<view class="flex align-center">
						<text>四川省遂宁市射洪市 {{productData.county_name}} {{ productData.village_name}}</text>
					</view>
				</view>
			</view>


			<view class="br10 px24 py36 border-box" v-if="getImg()[0]" style="background: #F5FFFB;">
				<view class="mb20 ml6">
					<text>{{productData.desc}}</text>
				</view>
				<view class="flex flex-wrap">
					<view class=" flex flex-center align-center mt6 " v-for="(item,index) in getImg()" :key="item"
						style="width:33.3%">
						<image style="height:192rpx; width:192rpx;" class="br16" :src="item" mode="">
						</image>
					</view>
				</view>
			</view>

		</view>

		<view class="font32 col2 fontw700 mt20">
			<text>农事记录</text>
		</view>

		<view class="mt20">
			<scroll-view scroll-x="true" class="bgWhite" style="white-space: nowrap;">
				<view class=" px26    " @click="tabClick(1)" style="display: inline-block; ">
					<view class="flex flex-column flex-around align-center " style="height:85rpx;">
						<view class="">
							<text>产品收货销售记录</text>
						</view>
						<view class="" v-if="tabActive==1"
							style=" height:2rpx; width:80rpx; background-color: orangered;"></view>
					</view>

				</view>


				<view class="px26" @click="tabClick(11)" style="display: inline-block; ">
					<view class="flex flex-column flex-around align-center " style="height:85rpx;">
						<view class="">
							<text>肥料购买及出入库记录</text>
						</view>
						<view class="" v-if="tabActive==11"
							style=" height:2rpx; width:80rpx; background-color: orangered;"></view>
					</view>
				</view>

				<view class="px26" @click="tabClick(2)" style="display: inline-block; ">
					<view class="flex flex-column flex-around align-center " style="height:85rpx;">
						<view class="">
							<text>肥料使用记录</text>
						</view>
						<view class="" v-if="tabActive==2"
							style=" height:2rpx; width:80rpx; background-color: orangered;"></view>
					</view>
				</view>


				<view class="px26" @click="tabClick(12)" style="display: inline-block; ">
					<view class="flex flex-column flex-around align-center " style="height:85rpx;">
						<view class="">
							<text>农药购买及出入库记录</text>
						</view>
						<view class="" v-if="tabActive==12"
							style=" height:2rpx; width:80rpx; background-color: orangered;"></view>
					</view>
				</view>

				<view class="px26" @click="tabClick(3)" style="display: inline-block; ">
					<view class="flex flex-column flex-around align-center " style="height:85rpx;">
						<view class="">
							<text>农药使用记录</text>
						</view>
						<view class="" v-if="tabActive==3"
							style=" height:2rpx; width:80rpx; background-color: orangered;"></view>
					</view>
				</view>

				<view class="px26" @click="tabClick(4)" style="display: inline-block; ">
					<view class="flex flex-column flex-around align-center " style="height:85rpx;">
						<view class="">
							<text>生产农事记录</text>
						</view>
						<view class="" v-if="tabActive==4"
							style=" height:2rpx; width:80rpx; background-color: orangered;"></view>
					</view>
				</view>
			</scroll-view>

			<view class="" v-if="tabActive==1">
				<uni-table ref="table" :loading="loading" border stripe emptyText="暂无更多数据">
					<uni-tr>
						<uni-th width="150" align="center">销售对象</uni-th>
						<uni-th width="150" align="center">销售数量</uni-th>
						<uni-th align="center">日期</uni-th>
					</uni-tr>
					<uni-tr v-for="(item, index) in shouhuoData" :key="index">
						<uni-td align="center">{{ item.xs_object }}</uni-td>
						<uni-td align="center">
							<view class="name">{{ item.xs_num }}</view>
						</uni-td>
						<uni-td align="center">{{ $u.timeFormat(item.time, 'yyyy年mm月dd日')  }}</uni-td>
					</uni-tr>
				</uni-table>
			</view>

			<view class="" v-if="tabActive==11">
				<uni-table ref="table" :loading="loading" border stripe emptyText="暂无更多数据">
					<uni-tr>
						<uni-th width="150" align="center">肥料名称</uni-th>
						<uni-th width="150" align="center">购买数量</uni-th>
						<uni-th width="150" align="center">登记证号</uni-th>
						<uni-th align="center">日期</uni-th>
					</uni-tr>
					<uni-tr v-for="(item, index) in chuRuKuData" :key="index">
						<uni-td align="center">{{ item.name }}</uni-td>
						<uni-td align="center">
							<view class="name">{{ item.buy_num }}</view>
						</uni-td>
						<uni-td align="center">
							<view class="name">{{ item.no }}</view>
						</uni-td>
						<uni-td align="center">{{ $u.timeFormat(item.time, 'yyyy年mm月dd日')  }}</uni-td>
					</uni-tr>
				</uni-table>
			</view>
			<!-- 肥料使用记录 -->
			<view class="" v-if="tabActive==2">
				<uni-table ref="table" :loading="loading" border stripe emptyText="暂无更多数据">
					<uni-tr>
						<uni-th width="150" align="center">地块名称</uni-th>
						<uni-th width="150" align="center">地块面积</uni-th>
						<uni-th width="150" align="center">肥料名称</uni-th>
						<uni-th width="150" align="center">每亩用量</uni-th>
						<uni-th align="center">日期</uni-th>
					</uni-tr>
					<uni-tr v-for="(item, index) in shouhuoData" :key="index">
						<uni-td align="center">{{ item.name }}</uni-td>
						<uni-td align="center">
							<view class="name">{{ item.dk_area }}</view>
						</uni-td>
						<uni-td align="center">
							<view class="name">{{ item.fl_name }}</view>
						</uni-td>
						<uni-td align="center">
							<view class="name">{{ item.mu_use }}</view>
						</uni-td>
						<uni-td align="center">{{ $u.timeFormat(item.time, 'yyyy年mm月dd日')  }}</uni-td>
					</uni-tr>
				</uni-table>

			</view>

			<!-- 农药使用记录 -->
			<view class="" v-if="tabActive==3">
				<uni-table ref="table" :loading="loading" border stripe emptyText="暂无更多数据">
					<uni-tr>
						<uni-th width="150" align="center">地块名称</uni-th> 
						<uni-th width="150" align="center">地块面积</uni-th>
						<uni-th width="150" align="center">农药名称</uni-th>
						<uni-th width="150" align="center">每亩用量</uni-th>
						<uni-th align="center">日期</uni-th>
					</uni-tr>
					<uni-tr v-for="(item, index) in shouhuoData" :key="index">
						<uni-td align="center">{{ item.name }}</uni-td>
						<uni-td align="center">
							<view class="name">{{ item.dk_area }}</view>
						</uni-td>
						<uni-td align="center">
							<view class="name">{{ item.ny_name }}</view>
						</uni-td>
						<uni-td align="center">
							<view class="name">{{ item.mu_use }}</view>
						</uni-td>
						<uni-td align="center">{{ $u.timeFormat(item.time, 'yyyy年mm月dd日')  }}</uni-td>
					</uni-tr>
				</uni-table>
			</view>
			<!-- 农药购买及出入库记录 -->
			<view class="" v-if="tabActive==12">
				<uni-table ref="table" :loading="loading" border stripe emptyText="暂无更多数据">
					<uni-tr>
						<uni-th width="150" align="center">农药名称</uni-th>
						<uni-th width="150" align="center">购买数量</uni-th>
						<uni-th width="150" align="center">出库数量</uni-th>
						<uni-th width="150" align="center">库存</uni-th>
						<uni-th align="center">日期</uni-th>
					</uni-tr>
					<uni-tr v-for="(item, index) in chuRuKuData" :key="index">
						<uni-td align="center">{{ item.name }}</uni-td>
						<uni-td align="center">
							<view class="name">{{ item.buy_num }}</view>
						</uni-td>
						<uni-td align="center">
							<view class="name">{{ item.out_num }}</view>
						</uni-td>
						<uni-td align="center">
							<view class="name">{{ item.stock }}</view>
						</uni-td>
						<uni-td align="center">{{ $u.timeFormat(item.time, 'yyyy年mm月dd日')  }}</uni-td>
					</uni-tr>
				</uni-table>
			</view>
			
			<view class="" v-if="tabActive==4">
				<uni-table ref="table" :loading="loading" border stripe emptyText="暂无更多数据">
					<uni-tr>
						<uni-th width="150" align="center">地块名称</uni-th>
						<uni-th width="150" align="center">地块面积</uni-th>
						<uni-th width="150" align="center">本季作物名称</uni-th>
						<uni-th width="150" align="center">前茬作物名称</uni-th>
						<uni-th align="center">日期</uni-th>
					</uni-tr>
					<uni-tr v-for="(item, index) in shouhuoData" :key="index">
						<uni-td align="center">{{ item.name }}</uni-td>
						<uni-td align="center">
							<view class="name">{{ item.dk_area }}</view>
						</uni-td>
						<uni-td align="center">
							<view class="name">{{ item.nzu_name }}</view>
						</uni-td>
						<uni-td align="center">
							<view class="name">{{ item.qc_name }}</view>
						</uni-td>
						<uni-td align="center">{{ $u.timeFormat(item.time, 'yyyy年mm月dd日')  }}</uni-td>
					</uni-tr>
				</uni-table>
			</view>
			<view class="bgWhite" v-if="total>=1">
				<uni-pagination  show-icon="true" :total="total" :current="page"></uni-pagination>
			</view>
		</view>
		
		
		<view class="font32 col2 fontw700 mt20">
			<text>巡查记录</text>
		</view>
		
		<view class="bgWhite mt20" >
			<uni-table ref="table" :loading="loading" border stripe emptyText="暂无更多数据">
				<uni-tr>
					
					<uni-th width="150" align="center">巡查人</uni-th>
					<uni-th width="150" align="center">生产主体</uni-th>
					<uni-th width="150" align="center">扣分项</uni-th>
					<!-- <uni-th width="150" align="center">图片</uni-th> -->
					<!-- <uni-th width="150" align="center">前茬作物名称</uni-th> -->
					<uni-th align="center">日期</uni-th>
				</uni-tr>
				<uni-tr v-for="(item, index) in xunChaData" :key="index">
					<uni-td align="center">{{ item.contacts }}</uni-td>
					<uni-td align="center">{{ item.main_name }}</uni-td>
					<uni-td align="center">
						<view class="name" v-for="item2 in item.subject" :key="item2.id">
							<text>{{item2.title}}</text>
							<text style="color:red;">-{{item2.score}}</text>
						</view>
					</uni-td>
					<!-- <uni-td align="center">
						<view class="name">
							<image :src="item" mode="" v-for="(item,index) in getImg(item.img)" :key="index"></image>
						</view>
					</uni-td> -->
					
					<uni-td align="center">{{ $u.timeFormat(item.time, 'yyyy年mm月dd日')  }}</uni-td>
				</uni-tr>
			</uni-table>
		</view>
		<view class="bgWhite" v-if="total>=1">
			<uni-pagination  show-icon="true" :total="total2" :current="page2"></uni-pagination>
		</view>


	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	export default {
		components: {},
		data() {
			return {
				productData: [],
				shouhuoData: [],
				id: '',
				page:1,
				limit:10,
				xunChaData:[],
				total:0,
				page2:1,
				limit2:10,
				tabActive: 1,
				chuRuKuData: []
			};
		},
		async onLoad(options) {
			this.id = options.id || ''

			await this.getData()
			this.getshouhuoData(this.tabActive)
			this.getXunChaData()
		},
		computed: {
			...mapState({
				userInfo: (state) => state.identity.userInfo
			}),
			
		},
		watch: {
			'tabActive': {
				handler(newVal) {
					if (newVal !== 11 && newVal !== 12) {
						this.getshouhuoData(newVal)
					} else {

						this.getChuRuData(newVal)
					}
				}
			}
		},

		methods: {
			back() {
				uni.navigateBack()
			},
			getData() {
				return new Promise(resolve => {
					this.$http({
						url: '/Data/product_detail',
						data: {
							id: this.id
						},
					}).then(res => {
						this.productData = res.data
						resolve("nnnn")
					})
				})

			},
			tabClick(index) {
				this.tabActive = index
			},
			getChuRuData(index) {

				return new Promise(resolve => {
					this.$http({
						url: '/Data/stock_log_list',
						data: {
							type: index - 10,
							uid: this.id,
							page:this.page,
							limit:this.limit
						},
					}).then(res => {
						this.chuRuKuData = res.data.list
							
						if(res.data.count==0){
							this.total = 0
						}else{
							this.total = Math.cell(res.data.count/this.limit)
						}
						resolve("nnnn")
					})
				})
			},
			
			getXunChaData(){
				return new Promise(resolve => {
					this.$http({
						url: '/Data/patrol_index',
						data: {
							uid: this.id,
							page:this.page2,
							limit:this.limit2,
							time:1
						},
					}).then(res => {
						this.xunChaData = res.data.list
						
						this.total2 = Math.cell(res.data.count/this.limit)
						resolve("nnnn")
					})
				})
			},
			getshouhuoData(index) {
				return new Promise(resolve => {
					this.$http({
						url: '/Data/product_log_list',
						data: {
							type: index,
							uid: this.id,
							page:this.page,
							limit:this.limit
						},
					}).then(res => {
						this.shouhuoData = res.data.list
						this.total = Math.cell(res.data.count/this.limit)
						resolve("nnnn")
					})
				})
			},
			getImg2(string){
				if (string && string !== '') {
					return this.productData.img.split(',')
				} else {
					return []
				}
			},
			getImg() {
				if (this.productData.img && this.productData.img !== '') {
					return this.productData.img.split(',')
				} else {
					return []
				}
			}
		}
	}
</script>

<style lang="scss">
	/deep/ .uni-nav-bar-text {
		font-size: 36rpx !important;
	}

	/deep/ .uni-navbar__header-container-inner {
		justify-content: left !important;
	}
</style>